<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>旅行社列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        #guide_ul li{
            margin-top: 15px;
        }
    </style>
</head>
<body>
<div id="aaa"></div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">旅行社列表</div>
                <div class="layui-card-body">
                    <div class="layui-form-item layui-form">

                        <div class="layui-inline">
                            <div class="layui-inline">
                                <div class="layui-btn-group test-table-operate-btn">
                                    <button class="layui-btn" data-type="addadmin">入驻旅行社</button>
                                </div>
                            </div>
                        </div>
                        {if !empty($res)}
                        <div class="layui-inline">
                            <label class="layui-form-label">旅行社名称</label>
                            <div class="layui-input-block">
                                <select name="team_name" lay-verify="" lay-search id="team_name">
                                    <option value="">请选择</option>
                                    {foreach $res as $k=>$v}
                                    <option value="{$v['team_name']}">{$v['team_name']}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <!--<div class="layui-input-block">-->
                            <!--<input type="text" name="tour_name" id="tour_name" placeholder="请输入" autocomplete="off" class="layui-input">-->
                            <!--</div>-->
                        </div>
                        {/if}
                        <!--<div class="layui-inline">-->
                            <!--<label class="layui-form-label">旅行社名称</label>-->
                            <!--<div class="layui-input-block">-->
                                <!--<input type="text" name="team_name" id="team_name" placeholder="请输入" autocomplete="off" class="layui-input">-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="layui-inline">
                            <label class="layui-form-label">旅行社电话</label>
                            <div class="layui-input-block">
                                <input type="text" name="team_phone" id="team_phone" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                         <div class="layui-inline">
                            <label class="layui-form-label">入驻时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="create_time" id="test6" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>   
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate">
                        <script type="text/html" id="is_display_switch">
                            <input type="checkbox" name="is_display" lay-skin="switch" lay-text="上架|下架" lay-filter="is_display_switch" value="{{ d.is_display }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.is_display == 0 ? 'checked' : '' }}>
                        </script>
                    </table>
                    <script type="text/html" id="test-table-operate-barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="showDetail">详细信息</a>
                        <a class="layui-btn layui-btn-xs" lay-event="default">订购须知</a>
                        <!--<a class="layui-btn layui-btn-normal layui-btn-xs" id="showImg" lay-event="showImg">旅行社图片</a>-->

                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editPassword">修改商户密码</a>
                        <a class="layui-btn layui-btn-green layui-btn-xs" lay-event="editPhone">修改手机号</a>
                        <a class="layui-btn layui-btn-green layui-btn-xs" lay-event="edit">修改</a>
                        <!--<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="yesPass">修改相册</a>-->
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="guide_del">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="contentShow" style="display:none;padding: 30px;">
    <p id="consultation"></p>
</div>
<!--导游信息详情-->
<div id="userDetail" style="display: none;padding:20px;">
    <div class="userDetailCen">
        <ul id="guide_ul">
            <li>
                <p class="p-user">常用手机号：<span id="send_tel"></span></p>
            </li>
            <li>
                <p class="p-user">营业时间：<span id="team_time"></span></p>
            </li>

            <li>
                <p class="p-user">法人身份证：</p>
                <img src="" id="fs_lagal1" style="width: 160px;height: 100px">
                <img src="" id="fs_lagal2" style="width: 160px;height: 100px;margin-left: 15px">
            </li>
            <li>
                <p class="p-user">营业执照：</p>
                <img src="" id="team_license_image" style="width: 160px;height: 100px"/>
            </li>
            <li>
                <p class="p-user">门头照：</p>
                <img src="" id="m_image" style="width: 160px;height: 100px"/>
            </li>
            <li>
                <p class="p-user">吧台照：</p>
                <img src="" id="b_image" style="width: 160px;height: 100px"/>
            </li>

            <li>
                <p class="p-user">实景图片：</p>
                <div id="live_action">

                </div>

            </li>
        </ul>
    </div>
</div>
<!--修改密码-->
<div id="editpassmodal"  style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="password" id="editPassword" placeholder="6-12位字母、数字、常用字符" autocomplete="off" class="layui-input">
                <input type="hidden" name="t_admin_id"  id="editPasswordUid">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" lay-verify="password" id="editPasswordAgin"  placeholder="再次输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-inline" style="left: 0;">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="editpasssubmit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
</div>

<!--修改手机号-->
<div id="editpassmodals"  style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="phone"  id="editPhone" value="" autocomplete="off" class="layui-input">
                <input type="hidden" name="h_admin_id"  id="hotel">
                <input type="hidden" name="hotel_name"  id="hotel_name">
            </div>
        </div>


        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-inline" style="left: 0;">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="editphonesubmit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
</div>

<!--提示信息-->
<div id="title"  style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <p style="text-align: center;font-size: 16px">该旅行社有未核销订单，下架后，将退款给用户，下架旅行社和所有旅行社的商品，不会再app或者pc端展示</p>

        <input type="hidden" id="ho_id"/>
        <div class="layui-form-item" style="margin-top: 30px">
            <label class="layui-form-label" style="width: 145px">待核销订单数：<span id="cancel_order" style="color: red"></span></label>
        </div>
        <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label" style="width: 150px">待退款订单数：<span id="refund_order" style="color: red"></span></label>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 150px">退款总金额：<span id="money" style="color: red"></span></label>
        </div>
        <div class="layui-form-item layui-layout-admin">
            <div style="text-align: center;margin-top: 20px">
                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="submits">确认</button>
                <button class="layui-btn layui-btn-primary" lay-filter="quxiao">取消</button>
            </div>
        </div>
    </form>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>

<script>
       layui.use('laydate', function(){
      var laydate = layui.laydate;  
      //日期范围
      laydate.render({
        elem: '#test6'
        ,range: true
      }); 
    }); 
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('Merchant/team')}"
            ,height: 'full-100'
            ,cols: [[
                {field:'team_id',width:80,align:'center', title: 'ID'}
                ,{field:'team_name',align:'center',title: '旅行社名称'}
                ,{field:'team_phone',align:'center',title: '旅行社电话'}
                ,{field:'send_tel',align:'center',title: '接收短信手机号'}
                ,{field:'team_address', align:'center', title: '旅行社地址',templet:function (d) {
                        return d.city+d.team_address
                    }}
            
                ,{field:'examine_time', align:'center', title: '入驻时间'}
                ,{field:'is_display', align:'center', title: '是否上架',templet: '#is_display_switch'}
                ,{align:'center',width:500, title: '操作', toolbar: '#test-table-operate-barDemo'}
            ]]
            ,page:true
            ,limit:10
        });

        form.render(null,'component-form-group');

        laydate.render({
            elem: '#search_time'
        });

        form.on('switch(is_display_switch)', function(obj){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);

            var is_display = this.checked ? '0' : '1';
            if(is_display==0){
                $.ajax({
                    url: "{:url('Merchant/isTeamShow')}",
                    type: 'post',
                    dataType: 'json',
                    data: {id:json.team_id,is_display:is_display},
                    success: function(info){
                        if (info.code === 1) {
                            layer.closeAll()

                        }else{
                            layer.msg(info.msg,{icon:2,time:2000},function(){
                                //layer.close(loading);
                                window.location.reload();
                            });
                        }
                    }
                })
            }else{
                //查看有无核销订单或者待确认的订单
                $.ajax({
                    url: "{:url('Merchant/isOrderTeam')}",
                    type: 'post',
                    dataType: 'json',
                    data: {id:json.team_id},
                    success: function(info){
                        if (info.code === 1) {
                            layer.open({
                                content: '该旅行社已无核销订单，下架后，将下架旅行社和所有旅行社的商品，不会再app或者pc端展示 确定要下架吗？'
                                ,btn: ['确定', '取消',]
                                ,yes: function(index, layero){
                                    $.ajax({
                                        url: "{:url('Merchant/isXjTeam')}",
                                        type: 'post',
                                        dataType: 'json',
                                        data: {id:json.team_id,is_display:1},
                                        success: function(info){
                                            if (info.code === 1) {
                                                layer.closeAll();
                                                window.location.reload();
                                            }else{
                                                layer.msg(info.msg,{icon:2,time:2000},function(){
                                                    //layer.close(loading);
                                                    window.location.reload();
                                                });
                                            }
                                        }
                                    })
                                }
                                ,btn2: function(index, layero){
                                    //按钮【按钮二】的回调
                                    layer.closeAll();
                                    window.location.reload();
                                    //return false 开启该代码可禁止点击该按钮关闭
                                }
                                ,cancel: function(){
                                    //右上角关闭回调
                                    layer.closeAll();
                                    window.location.reload();
                                    //return false 开启该代码可禁止点击该按钮关闭
                                }
                            });
                        }
                        if(info.code ===2){
                            $('#yes_order').html(info.q_sum);
                            $('#cancel_order').html(info.h_sun);
                            //$('#refund_order').html(info.t_sun);
                            $('#money').html(info.all_money);
                            $('#ho_id').val(info.id);
                            var editpassmodal = layer.open({
                                title:'下架信息提示'
                                ,type: 1
                                ,shadeClose: true
                                ,area: admin.screen() < 2 ? ['60%'] : ['500px']
                                ,content: $('#title')
                                ,cancel: function(index, layero){

                                    layer.close(index);
                                    window.location.reload();
                                    return false;
                                }
                            });
                        }
                    }
                })
            }

        });
        //取消
        form.on('submit(quxiao)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            layer.closeAll();
            window.location.reload();
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //确认并退款
        form.on('submit(submits)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var id = $("#ho_id").val();
            $.ajax({
                url: "{:url('Merchant/isRefundTeam')}",
                type: 'post',
                dataType: 'json',
                data: {id:id},
                success: function(info){
                    if (info === "1") {
                        layer.msg('下架成功',{icon:1,time:2000},function(){
                            layer.closeAll();
                            window.location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg('修改失败',{icon:2,time:1000})
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });



        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;
            if(obj.event === 'showDetail'){
                var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                var team_id = data.team_id;
                $.ajax({
                    url: "{:url('Merchant/teamInfoDetail')}",
                    type: 'post',
                    dataType: 'json',
                    data: {team_id:team_id},
                    success: function(data){
                        layer.close(loading);
                        if (data.code === 0) {

                            if(data.data.send_tel==''){
                                $('#send_tel').html('未设置');
                            }else{
                                $('#send_tel').html(data.data.send_tel);
                            }
                            if(data.data.team_start_time==''){
                                $('#team_time').html('未设置');
                            }else{
                                var team_time = data.data.team_start_time + '~' + data.data.team_end_time;
                                $('#team_time').html(team_time);
                            }
                            //处理身份证图片
                            var img_src = data.data.team_legel_image;
                            var img_src_arr = img_src.split(',');
                            $('#fs_lagal1').attr('src',img_src_arr[0]);
                            $('#fs_lagal2').attr('src',img_src_arr[1]);
                            //导游照片
                            $('#team_license_image').attr('src',data.data.team_license_image);
                           // $('#team_image').attr('src',data.data.team_image);
                            $('#m_image').attr('src',data.data.m_image);
                            $('#b_image').attr('src',data.data.b_image);
                            var live = data.data.team_image;
                            var live_src = live.split(',');
                            var show = '';

                            $.each(live_src,function (i) {
                                $("#live_action img").remove();
                                show+='<img src="'+live_src[i]+'" style="width: 160px;height: 100px;margin-left: 20px">';
                                $("#live_action").append(show);
                            })

                            var userDetailModal = layer.open({
                                title:'旅行社信息详情'
                                ,type: 1
                                ,shadeClose: true
                                ,area:['800px','500px']
                                ,content: $('#userDetail')
                            });
                        }else{
                            layer.msg('获取信息失败',{icon:2,time:1000});
                        }


                    }
                })
            } else if(obj.event === 'showImg'){
                $.ajax({
                    url: "{:url('Merchant/teamImage')}",
                    type: 'post',
                    dataType: 'json',
                    data: {id:data.team_id},
                    success: function(msg){
                        if (msg.code == 0) {
                            var arr  = msg.data;
                            let img_src_arr = [];
                            for (var i in arr) {
                                img_src_arr.push(arr[i].img_path)
                            }
                            console.log(img_src_arr);
                            var img_src_data = {};
                            img_src_data.title = '旅行社图片';
                            img_src_data.id = data.id;
                            img_src_data.start = 0;
                            img_src_data.data =[];

                            var src = {};

                            for(var i=0;i<img_src_arr.length;i++){
                                src = {};
                                var num = i+1;
                                src.alt = '旅行社图片'+ num;
                                src.pid = i;
                                src.src = img_src_arr[i];
                                src.thumb = img_src_arr[i];
                                console.log(src);
                                img_src_data.data.push(src);
                            }
                            layer.photos({
                                photos: img_src_data
                                ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                            });
                        }else{
                            layer.msg(msg.message,{time:1000});
                        }
                    }
                });
            } else if(obj.event === 'guide_del'){
                layer.confirm('确认删除"' + data.team_name + '"吗？', function(index){
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: "{:url('Merchant/delTeam')}",
                        type: 'post',
                        dataType: 'json',
                        data: {id:data.team_id},
                        success: function(msg){
                            layer.close(loading);
                            if (msg.code == 0) {
                                obj.del();
                                layer.close(index);
                            }else{
                                layer.msg(msg.message,{icon:2,time:1000});
                            }
                        }
                    });
                });
            } else if(obj.event === 'editPassword'){
                $('#editPasswordUid').val(data.t_admin_id);
                var editpassmodal = layer.open({
                    title:'修改商户密码'
                    ,type: 1
                    ,shadeClose: true
                    ,area: admin.screen() < 2 ? ['60%'] : ['500px']
                    ,content: $('#editpassmodal')
                });
            }else if(obj.event === 'edit'){
                window.location.href="{:url('Merchant/editTeam')}?id=" + data.team_id;
            }else if(obj.event === 'default'){
                window.open("/api/details/team/id/"+data.team_id+".html")
            }else if(obj.event === 'editPhone'){
                $('#hotel').val(data.team_id);
                $('#editPhone').val(data.send_tel);
                $('#hotel_name').val(data.team_name);
                var editphonemodal = layer.open({
                    title:'修改商户手机号'
                    ,type: 1
                    ,shadeClose: true
                    ,area: admin.screen() < 2 ? ['60%'] : ['500px']
                    ,content: $('#editpassmodals')
                });
            }

        });
        //修改密码提交
        form.on('submit(editpasssubmit)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var password = $('#editPassword').val();
            var passwordAgin = $('#editPasswordAgin').val();
            if (password !== passwordAgin){
                layer.close(loading);
                layer.msg('两次输入的密码不同',{icon:2,time:1000});
                return false;
            }
            $.ajax({
                url: "{:url('Merchant/editTeamPassword')}",
                type: 'post',
                dataType: 'text',
                data: {data:data.field},
                success: function(info){
                    if (info === "1") {
                        layer.msg('修改成功',{icon:1,time:2000},function(){
                            layer.closeAll()
                        });
                    }else{
                        layer.close(loading);
                        layer.msg('修改失败',{icon:2,time:1000})
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
         //修改手机号
         form.on('submit(editphonesubmit)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
          
            var phone = $('#editPhone').val();
            var myreg=/^1\d{10}$/;
            if (!myreg.test(phone)) {
                layer.msg('请输入正确的手机号',{icon:2,time:1000},function(){
                            layer.closeAll()
                        });
                return false;
            } 
            $.ajax({
                url: "{:url('Merchant/editTeamTel')}",
                type: 'post',
                dataType: 'text',
                data: {data:data.field},
                success: function(info){
                    if (info === "1") {
                        layer.msg('修改成功',{icon:1,time:2000},function(){
                            layer.closeAll()
                        });
                    }else if(info === "3"){
                         layer.msg('手机号已经存在',{icon:2,time:2000},function(){
                            layer.closeAll()
                        });
                    }
                    else if(info === "2"){
                        layer.close(loading);
                        layer.msg('修改失败',{icon:2,time:1000})
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        var $ = layui.$, active = {
            addadmin: function() {
                window.location.href="{:url('Merchant/teamAdd')}";
            },
            searchUserButton:function(){
                var team_name  = $('#team_name').val();
                var team_phone = $('#team_phone').val();
                var examine_time = $('#test6').val();

                table.reload('test-table-operate', {
                    where: {
                        team_name:team_name,
                        team_phone: team_phone,
                        examine_time: examine_time

                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            }
        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>


</body>
</html>